﻿namespace WinForms.ControlList.Systems
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using WinForms.Properties;
    using System.Reflection;

    public class FrmBackupAndResumeDb : Form
    {
        private Button btn_BackUp;
        private Button btn_Close;
        private Button btn_Resume;
        private IContainer components = null;
        private string copypath = (Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\dbbase\");
        private string datapath = (Directory.GetParent(Assembly.GetExecutingAssembly().Location) + @"\dates\");
        public const int HTCAPTION = 2;
        private Label lbl_LastBackTime;
        private Label lbl_LastBeisj;
        private Label lblTitle;
        private Panel pan_AllPanel;
        private Panel pan_AllPlanes;
        private Panel pan_Bottoms;
        private Panel pan_Dock;
        private Panel pan_DockBottom;
        private Panel pan_DockLeft;
        private Panel pan_DockRight;
        private Panel pan_Lefts;
        private Panel pan_Rights;
        private Panel pan_Table3;
        private Panel pan_Top;
        private Panel pan_TopLeft;
        private Panel pan_TopRight;
        private Panel pan_ZhongJian;
        private Panel pane_TopT;
        private Panel panel_Button;
        private Panel panel_JianGe;
        private Panel panel_JianGe1;
        private Panel panel9;
        public const int SC_MOVE = 0xf010;
        public const int WM_SYSCOMMAND = 0x112;

        public FrmBackupAndResumeDb()
        {
            this.InitializeComponent();
            base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            base.SetStyle(ControlStyles.UserPaint, true);
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            try
            {
                this.lbl_LastBackTime.Text = File.GetLastWriteTime(this.copypath + "dbfiles").ToString("yyyy-MM-dd hh:mm:ss");
            }
            catch (Exception)
            {
                this.lbl_LastBackTime.Text = "暂无备份";
            }
        }

        private void btn_BackUp_Click(object sender, EventArgs e)
        {
            try
            {
                Directory.CreateDirectory(this.copypath);
                File.Copy(this.datapath + "systems", this.copypath + "dbfiles", true);
                MessageBox.Show("数据备份成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (Exception)
            {
            }
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btn_Resume_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确定要还原数据吗?，这可能导致现有数据无法使用", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    File.Copy(this.copypath + "dbfiles", this.datapath + "systems", true);
                    MessageBox.Show("数据还原成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                catch (Exception)
                {
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.pan_DockLeft = new Panel();
            this.pan_Dock = new Panel();
            this.pan_AllPanel = new Panel();
            this.pan_AllPlanes = new Panel();
            this.panel_JianGe1 = new Panel();
            this.pan_Table3 = new Panel();
            this.lbl_LastBackTime = new Label();
            this.lbl_LastBeisj = new Label();
            this.panel_JianGe = new Panel();
            this.panel_Button = new Panel();
            this.btn_Resume = new Button();
            this.btn_Close = new Button();
            this.btn_BackUp = new Button();
            this.panel9 = new Panel();
            this.pan_Rights = new Panel();
            this.pan_Lefts = new Panel();
            this.pan_Bottoms = new Panel();
            this.pane_TopT = new Panel();
            this.pan_DockBottom = new Panel();
            this.pan_DockRight = new Panel();
            this.pan_Top = new Panel();
            this.pan_ZhongJian = new Panel();
            this.lblTitle = new Label();
            this.pan_TopRight = new Panel();
            this.pan_TopLeft = new Panel();
            this.pan_Dock.SuspendLayout();
            this.pan_AllPanel.SuspendLayout();
            this.pan_AllPlanes.SuspendLayout();
            this.pan_Table3.SuspendLayout();
            this.panel_Button.SuspendLayout();
            this.pan_Top.SuspendLayout();
            this.pan_ZhongJian.SuspendLayout();
            base.SuspendLayout();
            this.pan_DockLeft.BackColor = Color.FromArgb(0xaf, 0xbf, 190);
            this.pan_DockLeft.Dock = DockStyle.Left;
            this.pan_DockLeft.Location = new Point(0, 0);
            this.pan_DockLeft.Name = "pan_DockLeft";
            this.pan_DockLeft.Size = new Size(1, 0x80);
            this.pan_DockLeft.TabIndex = 0;
            this.pan_Dock.BackColor = Color.FromArgb(0, 0, 15, 0xff);
            this.pan_Dock.Controls.Add(this.pan_AllPanel);
            this.pan_Dock.Controls.Add(this.pan_DockBottom);
            this.pan_Dock.Controls.Add(this.pan_DockRight);
            this.pan_Dock.Controls.Add(this.pan_DockLeft);
            this.pan_Dock.Dock = DockStyle.Fill;
            this.pan_Dock.Location = new Point(0, 0x20);
            this.pan_Dock.Name = "pan_Dock";
            this.pan_Dock.Size = new Size(0x254, 0x80);
            this.pan_Dock.TabIndex = 5;
            this.pan_AllPanel.BackColor = Color.White;
            this.pan_AllPanel.Controls.Add(this.pan_AllPlanes);
            this.pan_AllPanel.Controls.Add(this.pan_Rights);
            this.pan_AllPanel.Controls.Add(this.pan_Lefts);
            this.pan_AllPanel.Controls.Add(this.pan_Bottoms);
            this.pan_AllPanel.Controls.Add(this.pane_TopT);
            this.pan_AllPanel.Dock = DockStyle.Fill;
            this.pan_AllPanel.Location = new Point(1, 0);
            this.pan_AllPanel.Name = "pan_AllPanel";
            this.pan_AllPanel.Size = new Size(0x252, 0x7f);
            this.pan_AllPanel.TabIndex = 3;
            this.pan_AllPlanes.Controls.Add(this.panel_JianGe1);
            this.pan_AllPlanes.Controls.Add(this.pan_Table3);
            this.pan_AllPlanes.Controls.Add(this.panel_JianGe);
            this.pan_AllPlanes.Controls.Add(this.panel_Button);
            this.pan_AllPlanes.Controls.Add(this.panel9);
            this.pan_AllPlanes.Dock = DockStyle.Fill;
            this.pan_AllPlanes.Location = new Point(10, 10);
            this.pan_AllPlanes.Name = "pan_AllPlanes";
            this.pan_AllPlanes.Size = new Size(0x23e, 0x6b);
            this.pan_AllPlanes.TabIndex = 4;
            this.panel_JianGe1.Dock = DockStyle.Top;
            this.panel_JianGe1.Location = new Point(0, 0x2d);
            this.panel_JianGe1.Name = "panel_JianGe1";
            this.panel_JianGe1.Size = new Size(0x23e, 10);
            this.panel_JianGe1.TabIndex = 0;
            this.pan_Table3.Controls.Add(this.lbl_LastBackTime);
            this.pan_Table3.Controls.Add(this.lbl_LastBeisj);
            this.pan_Table3.Dock = DockStyle.Top;
            this.pan_Table3.Location = new Point(0, 10);
            this.pan_Table3.Name = "pan_Table3";
            this.pan_Table3.Size = new Size(0x23e, 0x23);
            this.pan_Table3.TabIndex = 1;
            this.pan_Table3.Paint += new PaintEventHandler(this.pan_Table3_Paint);
            this.lbl_LastBackTime.AutoSize = true;
            this.lbl_LastBackTime.Location = new Point(160, 11);
            this.lbl_LastBackTime.Name = "lbl_LastBackTime";
            this.lbl_LastBackTime.Size = new Size(0, 12);
            this.lbl_LastBackTime.TabIndex = 1;
            this.lbl_LastBeisj.AutoSize = true;
            this.lbl_LastBeisj.Location = new Point(70, 11);
            this.lbl_LastBeisj.Name = "lbl_LastBeisj";
            this.lbl_LastBeisj.Size = new Size(0x53, 12);
            this.lbl_LastBeisj.TabIndex = 0;
            this.lbl_LastBeisj.Text = "最近备份时间:";
            this.panel_JianGe.Dock = DockStyle.Top;
            this.panel_JianGe.Location = new Point(0, 0);
            this.panel_JianGe.Name = "panel_JianGe";
            this.panel_JianGe.Size = new Size(0x23e, 10);
            this.panel_JianGe.TabIndex = 3;
            this.panel_Button.Controls.Add(this.btn_Resume);
            this.panel_Button.Controls.Add(this.btn_Close);
            this.panel_Button.Controls.Add(this.btn_BackUp);
            this.panel_Button.Dock = DockStyle.Bottom;
            this.panel_Button.Location = new Point(0, 0x3b);
            this.panel_Button.Name = "panel_Button";
            this.panel_Button.Size = new Size(0x23e, 0x2b);
            this.panel_Button.TabIndex = 6;
            this.panel_Button.Paint += new PaintEventHandler(this.panel_Button_Paint);
            this.btn_Resume.Location = new Point(250, 10);
            this.btn_Resume.Name = "btn_Resume";
            this.btn_Resume.Size = new Size(0x4b, 0x17);
            this.btn_Resume.TabIndex = 7;
            this.btn_Resume.Text = "还 原";
            this.btn_Resume.UseVisualStyleBackColor = true;
            this.btn_Resume.Click += new EventHandler(this.btn_Resume_Click);
            this.btn_Close.Location = new Point(0x16e, 10);
            this.btn_Close.Name = "btn_Close";
            this.btn_Close.Size = new Size(0x4b, 0x17);
            this.btn_Close.TabIndex = 6;
            this.btn_Close.Text = "关 闭";
            this.btn_Close.UseVisualStyleBackColor = true;
            this.btn_Close.Click += new EventHandler(this.btn_Close_Click);
            this.btn_BackUp.Location = new Point(0x86, 10);
            this.btn_BackUp.Name = "btn_BackUp";
            this.btn_BackUp.Size = new Size(0x4b, 0x17);
            this.btn_BackUp.TabIndex = 5;
            this.btn_BackUp.Text = "备 份";
            this.btn_BackUp.UseVisualStyleBackColor = true;
            this.btn_BackUp.Click += new EventHandler(this.btn_BackUp_Click);
            this.panel9.Dock = DockStyle.Bottom;
            this.panel9.Location = new Point(0, 0x66);
            this.panel9.Name = "panel9";
            this.panel9.Size = new Size(0x23e, 5);
            this.panel9.TabIndex = 3;
            this.pan_Rights.Dock = DockStyle.Right;
            this.pan_Rights.Location = new Point(0x248, 10);
            this.pan_Rights.Name = "pan_Rights";
            this.pan_Rights.Size = new Size(10, 0x6b);
            this.pan_Rights.TabIndex = 3;
            this.pan_Lefts.Dock = DockStyle.Left;
            this.pan_Lefts.Location = new Point(0, 10);
            this.pan_Lefts.Name = "pan_Lefts";
            this.pan_Lefts.Size = new Size(10, 0x6b);
            this.pan_Lefts.TabIndex = 2;
            this.pan_Bottoms.Dock = DockStyle.Bottom;
            this.pan_Bottoms.Location = new Point(0, 0x75);
            this.pan_Bottoms.Name = "pan_Bottoms";
            this.pan_Bottoms.Size = new Size(0x252, 10);
            this.pan_Bottoms.TabIndex = 1;
            this.pane_TopT.Dock = DockStyle.Top;
            this.pane_TopT.Location = new Point(0, 0);
            this.pane_TopT.Name = "pane_TopT";
            this.pane_TopT.Size = new Size(0x252, 10);
            this.pane_TopT.TabIndex = 0;
            this.pan_DockBottom.BackColor = Color.FromArgb(0xaf, 0xbf, 190);
            this.pan_DockBottom.Dock = DockStyle.Bottom;
            this.pan_DockBottom.Location = new Point(1, 0x7f);
            this.pan_DockBottom.Name = "pan_DockBottom";
            this.pan_DockBottom.Size = new Size(0x252, 1);
            this.pan_DockBottom.TabIndex = 2;
            this.pan_DockRight.BackColor = Color.FromArgb(0xaf, 0xbf, 190);
            this.pan_DockRight.Dock = DockStyle.Right;
            this.pan_DockRight.Location = new Point(0x253, 0);
            this.pan_DockRight.Name = "pan_DockRight";
            this.pan_DockRight.Size = new Size(1, 0x80);
            this.pan_DockRight.TabIndex = 1;
            this.pan_Top.Controls.Add(this.pan_ZhongJian);
            this.pan_Top.Controls.Add(this.pan_TopRight);
            this.pan_Top.Controls.Add(this.pan_TopLeft);
            this.pan_Top.Dock = DockStyle.Top;
            this.pan_Top.Location = new Point(0, 0);
            this.pan_Top.Name = "pan_Top";
            this.pan_Top.Size = new Size(0x254, 0x20);
            this.pan_Top.TabIndex = 4;
            this.pan_ZhongJian.BackgroundImage = Resources.uc_title_2;
            this.pan_ZhongJian.Controls.Add(this.lblTitle);
            this.pan_ZhongJian.Dock = DockStyle.Fill;
            this.pan_ZhongJian.Location = new Point(0x1f, 0);
            this.pan_ZhongJian.Name = "pan_ZhongJian";
            this.pan_ZhongJian.Size = new Size(560, 0x20);
            this.pan_ZhongJian.TabIndex = 2;
            this.pan_ZhongJian.MouseDown += new MouseEventHandler(this.pan_ZhongJian_MouseDown);
            this.lblTitle.AutoSize = true;
            this.lblTitle.BackColor = Color.FromArgb(0, 0, 15, 0xff);
            this.lblTitle.Font = new Font("宋体", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0x86);
            this.lblTitle.ForeColor = Color.FromArgb(0x3b, 0x56, 20);
            this.lblTitle.Location = new Point(6, 8);
            this.lblTitle.Name = "lblTitle";
            this.lblTitle.Size = new Size(0x4d, 13);
            this.lblTitle.TabIndex = 0;
            this.lblTitle.Text = "备份数据库";
            this.pan_TopRight.BackgroundImage = Resources.uc_title_1;
            this.pan_TopRight.Dock = DockStyle.Right;
            this.pan_TopRight.Location = new Point(0x24f, 0);
            this.pan_TopRight.Name = "pan_TopRight";
            this.pan_TopRight.Size = new Size(5, 0x20);
            this.pan_TopRight.TabIndex = 1;
            this.pan_TopLeft.BackgroundImage = Resources.uc_title;
            this.pan_TopLeft.Dock = DockStyle.Left;
            this.pan_TopLeft.Location = new Point(0, 0);
            this.pan_TopLeft.Name = "pan_TopLeft";
            this.pan_TopLeft.Size = new Size(0x1f, 0x20);
            this.pan_TopLeft.TabIndex = 0;
            this.pan_TopLeft.MouseDown += new MouseEventHandler(this.pan_TopLeft_MouseDown);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x254, 160);
            base.Controls.Add(this.pan_Dock);
            base.Controls.Add(this.pan_Top);
            base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FrmBackupAndResumeDb";
            base.ShowInTaskbar = false;
            this.pan_Dock.ResumeLayout(false);
            this.pan_AllPanel.ResumeLayout(false);
            this.pan_AllPlanes.ResumeLayout(false);
            this.pan_Table3.ResumeLayout(false);
            this.pan_Table3.PerformLayout();
            this.panel_Button.ResumeLayout(false);
            this.pan_Top.ResumeLayout(false);
            this.pan_ZhongJian.ResumeLayout(false);
            this.pan_ZhongJian.PerformLayout();
            base.ResumeLayout(false);
        }

        private void pan_Table3_Paint(object sender, PaintEventArgs e)
        {
            this.Panel_ResetPaint(e, this.pan_Table3, Color.FromArgb(0xca, 0xc9, 0xce), 1, 1, 1, 1);
        }

        private void pan_TopLeft_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(base.Handle, 0x112, 0xf012, 0);
        }

        private void pan_ZhongJian_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(base.Handle, 0x112, 0xf012, 0);
        }

        private void panel_Button_Paint(object sender, PaintEventArgs e)
        {
            this.Panel_ResetPaint(e, this.panel_Button, Color.FromArgb(0xca, 0xc9, 0xce), 1, 1, 1, 1);
        }

        private void Panel_ResetPaint(PaintEventArgs e, Panel panel, Color color, int leftBoder, int topBoder, int rightBoder, int bottomBoder)
        {
            ControlPaint.DrawBorder(e.Graphics, panel.ClientRectangle, color, leftBoder, ButtonBorderStyle.Solid, color, topBoder, ButtonBorderStyle.Solid, color, rightBoder, ButtonBorderStyle.Solid, color, bottomBoder, ButtonBorderStyle.Solid);
        }

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
    }
}

